package com.deer.wms.base.system.web.bill;

import com.deer.wms.base.system.model.bill.BillInMasterCriteria;
import com.deer.wms.base.system.model.bill.BillInMasterDto;
import com.deer.wms.base.system.model.bill.MaterialInfo;
import com.deer.wms.base.system.model.bill.MaterialInfoCriteria;
import com.deer.wms.base.system.model.task.TaskInfoCriteria;
import com.deer.wms.base.system.model.task.TaskInfoDto;
import com.deer.wms.base.system.service.bill.IBillInDetailService;
import com.deer.wms.base.system.service.bill.IBillInMasterService;
import com.deer.wms.base.system.service.bill.WorkMasterService;
import com.deer.wms.base.system.service.box.IBoxItemService;
import com.deer.wms.base.system.service.item.IItemInfoService;
import com.deer.wms.base.system.service.task.BillInTaskInfoService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李帅辰
 * @date 2021/6/9 14:56
 */
@Controller
@RequestMapping("/in/materialWork")
public class MaterialBillInWorkController extends BaseController {


    private String prefix = "in/materialWork";

    @Autowired
    private BillInTaskInfoService billInTaskInfoService;

    //@RequiresPermissions("in:materialWork:view")
    @GetMapping()
    public String materialWork() {
        return prefix + "/materialWork";
    }

    /*入库作业列表*/
    //@RequiresPermissions("in:materialWork:list")
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(TaskInfoDto taskInfoDto) {
        startPage();
        List<TaskInfoDto> taskInfoList = billInTaskInfoService.findTaskInfoList(taskInfoDto);
        return getDataTable(taskInfoList);
    }


    @RequiresPermissions("in:materialWork:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskInfoCriteria taskInfoCriteria) {
        List<TaskInfoDto> billInErrorList = billInTaskInfoService.findBillInErrorList(taskInfoCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(billInErrorList, "晶棒入库作业信息");
    }
    /**
     * 导出列表
     */
    @RequiresPermissions("in:materialWork:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam String ids) {
        List<TaskInfoDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            TaskInfoCriteria b=new TaskInfoCriteria ();
            b.setId(Integer.parseInt(s));
            List<TaskInfoDto> list = billInTaskInfoService.findBillInErrorList(b);
            for (TaskInfoDto bs:list
            ) {
                byIds.add(bs);
            }




        }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(byIds, "晶棒入库作业信息");
    }

}
